package com.example.hblog.module.controller;

import com.example.hblog.Result;
import com.example.hblog.module.pojo.User;
import com.example.hblog.module.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@Slf4j
@RequestMapping("api")
public class UserController {
    @Autowired
    private UserService userService;


    /*用户登录*/
    @PostMapping("/updateUser")
    public Result updateUser(@RequestBody User user){
        try{
            userService.updateUser(user);
            return new Result(200,"修改成功",null);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
            return new Result(400,"修改失败,"+e.getMessage(),null);

        }
    }

    @ResponseBody
    @GetMapping("/findUserByPhone")
    public Result findUserByPhone(String phone){
        try{
            User user = userService.findUserByPhone(phone);
            return new Result(200,"获取成功",user);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(400,"获取失败",null);
        }
    }

    @GetMapping("/myself")
    @ResponseBody
    public Result myself(){
        return new Result(200,"哒哒哒嘎嘎嘎嘎",userService.mySelf());
    }

}
